package com.example.museum.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.museum.entity.CulturalInfo;
import com.example.museum.mapper.CulturalInfoMapper;
import com.example.museum.service.CulturalInfoService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class CulturalInfoServiceImpl extends ServiceImpl<CulturalInfoMapper, CulturalInfo> implements CulturalInfoService {

    @Override
    public Page<CulturalInfo> getPageList(int page, int pageSize, String query) {
        Page<CulturalInfo> pageParam = new Page<>(page, pageSize);
        return baseMapper.selectPageWithSearch(pageParam, query);
    }

    @Override
    public boolean addCulturalInfo(CulturalInfo culturalInfo) {
        // 设置创建时间和更新时间
        LocalDateTime now = LocalDateTime.now();
        culturalInfo.setCreateTime(now);
        culturalInfo.setUpdateTime(now);
        
        return save(culturalInfo);
    }

    @Override
    public CulturalInfo getInfoById(Long id) {
        return getById(id);
    }

    @Override
    public boolean updateCulturalInfo(CulturalInfo culturalInfo) {
        // 设置更新时间
        culturalInfo.setUpdateTime(LocalDateTime.now());
        
        return updateById(culturalInfo);
    }

    @Override
    public boolean deleteCulturalInfo(Long id) {
        return removeById(id);
    }
}